package com.sweet.mealon.face.daily.lock.concurence.countdown;

import lombok.Data;

import java.util.concurrent.CountDownLatch;

/**
 * faceDaily
 * countDownLatch这个类使一个线程等待其他线程各自执行完毕后再执行
 * @Author: craizer.huang
 * @Date: 2021/5/1 8:25
 **/
@Data
public class CountDownLatchDemo {



    public static void main(String[] args) throws InterruptedException {
        final CountDownLatch countDownLatch = new CountDownLatch(5);
        for (int i = 0; i < 10; i++) {
            CountDownThread countDownThread = new CountDownThread(countDownLatch);
            Thread t = new Thread(countDownThread,String.valueOf(i));
            t.start();
        }
        countDownLatch.await();
        System.out.println(String.format("%s finish",Thread.currentThread().getName()));


    }

}
